#!/bin/bash

outputDirectory="/media/hop-siup/backup"
unique=""

function storePendrak {
	if [ -d "/media/PENDRAK 4GB" ]; then
		echo "Jest pendrak..."
		if [ ! -d "/media/PENDRAK 4GB/backup" ]; then
			echo "Trzeba utworzyc katalog..."
			mkdir "/media/PENDRAK 4GB/backup"
			echo "Katalog utworzony"
		fi
		echo "Kopiowanie archiwum na pendraka..."
		cp $1 "/media/PENDRAK 4GB/backup/"
	fi
}

function startBackup {
	fileList=$1					#ex. "/media/hop-siup/phone_backup/hazel"
	#fileList=$2					#ex. "$fileList /media/hop-siup/phone_backup/E51"
	archiveName=$2				#ex. "backup_phone_${unique}.7z"

	7z a -t7z "${outputDirectory}/${archiveName}" ${fileList}
	
	storePendrak "${outputDirectory}/${archiveName}"
}

svnadmin dump /media/hop-siup/svnrepo > "${outputDirectory}/svnrepo_linux.dump"
storePendrak "${outputDirectory}/svnrepo_linux.dump"

#~/backup_home.sh
#startBackup "/home/piotrek/" "/media/hop-siup/backup" "backup_home_${unique}.7z"

#~/backup_el.sh
startBackup "/media/hop-siup/proj" "backup_el_${unique}.7z"

#~/backup_phone.sh
startBackup "/media/hop-siup/phone_backup/hazel /media/hop-siup/phone_backup/E51" "backup_phone_${unique}.7z"

#~/backup_doc.sh
startBackup "/media/hop-siup/doc/" "backup_doc_${unique}.7z"

#svn repository backup
startBackup "/media/hop-siup/svnrepo" "backup_svnrepo_${unique}.7z"

svnadmin dump file:///media/hop-siup/svnrepo > "${outputDirectory}/svnrepo_linux.dump"
storePendrak "${outputDirectory}/svnrepo_linux.dump"

